const defaultImg = `http://www.rjmart.cn/download/reagent/image/d15682ec/3fd93baa-7955-4de4-82c8-73c310c44e1f.png`;

export default class ImageWithError extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			img_error: false
		};
	}

	render() {
		const { src, className, style } = this.props;
		const { img_error } = this.state;
		if (!src) {
			return (
				<img
					style={style}
					className={className}
					src={defaultImg}
					alt=""
				/>
			);
		}
		return (
			<img
				className={className}
				style={style}
				onError={() => {
					this.setState({
						img_error: true
					});
				}}
				src={img_error ? defaultImg : src}
				alt=""
			/>
		);
	}
}

export class EmptyImage extends React.Component {
	render() {
		const {  src, className, style } = this.props;

		return (
			<img className={className} style={style} src={defaultImg} alt=""/>
		);
	}
}
